<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios.min.js"></script>
    <script src="../../js/dayjs.min.js"></script>
    <link rel="stylesheet" href="../../plugins/element_UI/index.css">
    <script src="../../plugins/element_UI/index.js"></script>
</head>
<body>
<style>
    .el-table .warning-row {
        background: #f9c855;
    }

    .el-table .error-row {
        background: #909399;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }

    .el-checkbox {
        color: #606266;
        font-weight: 500;
        font-size: 14px;
        cursor: pointer;
        user-select: none;
        margin-right: 0px;
    }

    .sw.el-checkbox-button.is-disabled .el-checkbox-button__inner {
        color: #C0C4CC;
        cursor: not-allowed;
        background-image: none;
        background-color: #67c23a;
        border-color: #67c23a;
        -webkit-box-shadow: none;
        box-shadow: none;
    }

    .xw.el-checkbox-button.is-disabled .el-checkbox-button__inner {
        color: #C0C4CC;
        cursor: not-allowed;
        background-image: none;
        background-color: #e57e31;
        border-color: #e57e31;
        -webkit-box-shadow: none;
        box-shadow: none;
    }
    .ymz.el-checkbox-button.is-disabled .el-checkbox-button__inner {
        color: #C0C4CC;
        cursor: not-allowed;
        background-image: none;
        background-color: #f56c6c;
        border-color: #f56c6c;
        -webkit-box-shadow: none;
        box-shadow: none;
    }

    .group.element.style {
        background-color: rgba(255,255,255,.5);
    }

    element.style {
        background-color: rgba(255,255,255,.5);
    }

    .el-table .cell {
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        word-break: break-all;
        line-height: 15px;
        padding-right: 5px;
    }
    .bg-purple-1 {
        background: #67c23a;
    }
    .bg-purple-2 {
        background: #e57e31;
    }
    .bg-purple-3 {
        background: #f56c6c;
    }
    .grid-content {
        border-radius: 4px;
        margin-left: 10px;
        min-height: 1px;
        height: 20px;
    }
    .el-date-editor--daterange.el-input, .el-date-editor--daterange.el-input__inner, .el-date-editor--timerange.el-input, .el-date-editor--timerange.el-input__inner {
        width: 225px;
    }

    .el-input__inner {
        -webkit-appearance: none;
        background-color: #FFF;
        background-image: none;
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        color: #606266;
        display: inline-block;
        font-size: inherit;
        height: 32px;
        line-height: 40px;
        outline: 0;
        padding: 0 15px;
        -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
        transition: border-color .2s cubic-bezier(.645,.045,.355,1);
        width: 100%;
    }
    /*.el-table .cell {*/
    /*    -webkit-box-sizing: border-box;*/
    /*    box-sizing: border-box;*/
    /*    overflow: hidden;*/
    /*    text-overflow: ellipsis;*/
    /*    white-space: normal;*/
    /*    word-break: break-all;*/
    /*    line-height: 15px;*/
    /*    padding-right: 10px;*/
    /*}*/
    #page {
        height: 40px;
        line-height: 40px;
        position: fixed;
        bottom: 34px;
        width: 100%;
        text-align: start;
        /*background: #393D49;*/
        color: #fff;
        font-family: Arial;
        font-size: 12px;
        letter-spacing: 1px;
    }
</style>
<div id="app">
    <el-row  type="flex" justify="start">
            <el-input
                    placeholder="医生姓名模糊查询"
                    v-model="doctorName"
                    style="width: fit-content"
                    @change="init"
                    clearable>
            </el-input>
        <template>
            <el-radio v-model="status" label="1" @change="init">不同步</el-radio>
            <el-radio v-model="status" label="0" @change="init">同步</el-radio>
            <el-radio v-model="status" label="2" @change="init">全部</el-radio>
        </template>
            <el-button type="primary" icon="el-icon-search" @click="init">搜索</el-button>
            <el-button type="primary" @click="extractHisData">抽取排班数据</el-button>
            <el-button type="primary" @click="createSchedulingBatch">批量生成排版</el-button>
        <div class="grid-content bg-purple-1">所有渠道开放</div>
        <div class="grid-content bg-purple-2">仅自有渠道开放</div>
        <div class="grid-content bg-purple-3">仅VIP开放</div>
    </el-row>
    <template>
        <el-table
                :data="tableData"
                type="index"
                style="width: 100%"
                :max-height="tableHeight"
                border
                ref="table"
                :cell-style="cellStyle"
                :row-class-name="tableRowClassName"
                @current-change="handleCurrentChange"
                size="mini">
            <el-table-column
                    fixed
                    prop="hospitalId"
                    label="医院"
                    v-if="hospitalId==null"
                    sortable
                    align="center"
                    :formatter=formatterHospital
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="systemid"
                    label="ID"
                    align="center"
                    sortable
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="depName"
                    label="科室名称"
                    align="center"
                    sortable
                    width="100">
            </el-table-column>
            <el-table-column
                    prop="yishengbm"
                    label="编码"
                    align="center"
                    sortable
                    cell-style="#00B83F"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="doctorName"
                    label="医生姓名"
                    align="center"
                    sortable
                    cell-style="#00B83F"
                    width="100">
            </el-table-column>

            <el-table-column
                    prop="riqi1"
                    label="星期一"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled >
                        <el-checkbox-button v-model="scope.row.riqi1!='√'"
                                            :class="{ sw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.sw == 0, xw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.sw == 1,'ymz': scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi1!='√'"
                                            :class="{ sw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.xw == 0, xw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.xw == 1,'ymz': scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi1=='√'"
                                            :class="{ sw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.ymz == 0, xw: scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.ymz == 1,'ymz': scope.row.riqi1Wrapper!=null && scope.row.riqi1Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi2"
                    label="星期二"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi2!='√'"
                                            :class="{ sw: scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.sw == 0, 'xw': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.sw == 1,'ymz': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi2!='√'"
                                            :class="{ sw: scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.xw == 0, 'xw': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.xw == 1,'ymz': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi2=='√'"
                                            :class="{ sw: scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.ymz == 0, 'xw': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.ymz == 1,'ymz': scope.row.riqi2Wrapper!=null && scope.row.riqi2Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi3"
                    label="星期三"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi3!='√'"
                                            :class="{ sw: scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.sw == 0, 'xw': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.sw == 1,'ymz': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi3!='√'"
                                            :class="{ sw: scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.xw == 0, 'xw': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.xw == 1,'ymz': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi3=='√'"
                                            :class="{ sw: scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.ymz == 0, 'xw': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.ymz == 1,'ymz': scope.row.riqi3Wrapper!=null && scope.row.riqi3Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi4"
                    label="星期四"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi4!='√'"
                                            :class="{ sw: scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.sw == 0, 'xw': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.sw == 1,'ymz': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.sw ==2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi4!='√'"
                                            :class="{ sw: scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.xw == 0, 'xw': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.xw == 1,'ymz': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi4=='√'"
                                            :class="{ sw: scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.ymz == 0, 'xw': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.ymz == 1,'ymz': scope.row.riqi4Wrapper!=null && scope.row.riqi4Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi5"
                    label="星期五"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi5!='√'"
                                            :class="{ sw: scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.sw == 0, 'xw': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.sw == 1,'ymz': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi5!='√'"
                                            :class="{ sw: scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.xw == 0, 'xw': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.xw == 1,'ymz': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi5=='√'"
                                            :class="{ sw: scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.ymz == 0, 'xw': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.ymz == 1,'ymz': scope.row.riqi5Wrapper!=null && scope.row.riqi5Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi6"
                    label="星期六"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi6!='√'"
                                            :class="{ sw: scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.sw == 0, 'xw': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.sw == 1,'ymz': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi6!='√'"
                                            :class="{ sw: scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.xw == 0, 'xw': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.xw == 1,'ymz': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi6=='√'"
                                            :class="{ sw: scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.ymz == 0, 'xw': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.ymz == 1,'ymz': scope.row.riqi6Wrapper!=null && scope.row.riqi6Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="riqi7"
                    label="星期日"
                    align="center"
                    :formatter="formatterWeek"
                    width="150">
                <template slot-scope="scope">
                    <el-checkbox-group size="mini" disabled>
                        <el-checkbox-button v-model="scope.row.riqi7!='√'"
                                            :class="{ sw: scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.sw == 0, 'xw': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.sw == 1,'ymz': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.sw == 2 }">
                            上
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi7!='√'"
                                            :class="{ sw: scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.xw == 0, 'xw': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.xw == 1,'ymz': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.xw == 2 }">
                            下
                        </el-checkbox-button>
                        <el-checkbox-button v-model="scope.row.riqi7=='√'"
                                            :class="{ sw: scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.ymz == 0, 'xw': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.ymz == 1,'ymz': scope.row.riqi7Wrapper!=null && scope.row.riqi7Wrapper.ymz == 2 }">
                            夜
                        </el-checkbox-button>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column
                    prop="guahaofei"
                    label="挂号费(元)"
                    align="center"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="zhenliaofei"
                    label="诊疗费(元)"
                    align="center"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="start"
                    label="开始"
                    align="center"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="end"
                    label="结束"
                    align="center"
                    width="80">
            </el-table-column>
<!--            <el-table-column-->
<!--                    prop="xianzhisl"-->
<!--                    label="号源总数"-->
<!--                    align="center"-->
<!--                    width="80">-->
<!--            </el-table-column>-->

            <el-table-column
                    fixed="right"
                    align="center"
                    label="操作"
                    width="120">
                <template slot-scope="scope">

                    <el-button
                            @click.native.prevent="detail(scope.$index,scope.row)"
                            type="primary" :disabled="scope.row.status==1 || scope.row.status==2"
                            size="mini" circle>详情
                    </el-button>
                    <el-tooltip content="主动注销的排班不予以同步自动开启" placement="top">
                        <el-switch
                                v-model="scope.row.sync==0"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                @change="deleteRow(scope.$index,scope.row)"
                        >
                        </el-switch>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
    </template>
    <div id="page">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentPageChange"
                :current-page="currentPage"
                :page-sizes="[5, 10, 15, 30]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</div>
</body>
<script>
    let app = new Vue({
        el: '#app',
        data() {
            let checkAppointmentBegin = (rule, value, callback) => {
                if (value == undefined || value == null) {
                    return callback(new Error('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test(value)) {
                        if (parseInt(value) < parseInt(this.ruleForm.amount)) {

                        } else {
                            return callback(new Error('预约起始号不能大于号源总数'));
                        }
                        if (parseInt(this.ruleForm.appointmentAmount) <= parseInt(this.ruleForm.amount) - parseInt(value) + 1) {

                        } else {
                            return callback(new Error('预约号数量不能大于号源总数减去起始号量'));
                        }
                        callback();
                    } else {
                        return callback(new Error('请输入正确预约起始号'));
                    }
                }
            };
            let checkAppointmentAmount = (rule, value, callback) => {
                console.log(value)
                if (value == undefined || value == null) {
                    return callback(new Error('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test(value)) {
                        console.log(value, parseInt(this.ruleForm.amount) - parseInt(this.ruleForm.appointmentBegin), this.ruleForm.amount, this.ruleForm.appointmentBegin)
                        if (parseInt(value) <= parseInt(this.ruleForm.amount) - parseInt(this.ruleForm.appointmentBegin) + 1) {
                            callback();
                        } else {
                            return callback(new Error('预约号数量不能大于号源总数减去起始号量'));
                        }
                    } else {
                        return callback(new Error('请输入正确预约起始号'));
                    }
                }
            };
            let checkAmount = (rule, value, callback) => {
                console.log(value)
                if (value == undefined || value == null) {
                    return callback(new Error('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test(value)) {
                        if (parseInt(this.ruleForm.amount) >= parseInt(this.ruleForm.appointmentBegin)) {
                            callback();
                        } else {
                            return callback(new Error('号源数量不能小于预约号数量'));
                        }
                    } else {
                        return callback(new Error('请输入正确号源数'));
                    }
                }
            };
            let checkAverageVisitTime = (rule, value, callback) => {
                console.log(value)
                if (value == undefined || value == null) {
                    return callback(new Error('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test(value)) {
                        if (parseInt(value) < 10) {
                            callback();
                        } else {
                            return callback(new Error('请输入正确平均就诊时间'));
                        }
                    } else {
                        return callback(new Error('请输入正确平均就诊时间'));
                    }
                }
            };
            return {
                pickerOptions0: {
                    disabledDate: (time) => {
                        if (this.ruleForm.dueDate != "") {
                            return time.getTime() < Date.now() - 8.64e7 && time.getTime() > this.ruleForm.dueDate;
                        } else {
                            return time.getTime() < Date.now() - 8.64e7;
                        }
                    }
                },
                pickerOptions1: {
                    disabledDate: (time) => {
                        return time.getTime() < this.ruleForm.effectiveDate && time.getTime() < Date.now() - 8.64e7;
                    }
                },
                sourceTableData: [],  // 原始数据
                hospitalId: JSON.parse(localStorage.getItem("user")).hospitalId,
                tableData: [],
                currentPage: 1,
                pageSize:  15,
                totalPage: 1,
                total:1000,
                scrollDistance: 0,
                tableHeight: 100,
                isEdit: false,
                depName: "",
                doctorName: "",
                status: '2',
                isLabel: "",
                loading: false,
                currentUpRow: null,
                hospitals: [],
                departments: [],
                bindInfos: [],
                doctors: [],
                week: '',
                optionTime: {
                    start: '07:30:00',
                    step: '00:15:00',
                    end: '21:30:00',
                    minTime: '07:30:00',
                    maxTime: '12:30:00'
                },
                comingWeeksList: [{name: '预设一周排班', id: 1},
                    {name: '预设两周排班', id: 2},
                    {name: '预设三周排班', id: 3},
                    {name: '预设四周排班', id: 4},
                    {name: '预设五周排班', id: 5},
                ],
                weekList: [{
                    name: '全部',
                    id: null
                }, {
                    name: '周一',
                    id: 1
                }, {
                    name: '周二',
                    id: 2
                }, {
                    name: '周三',
                    id: 3
                }, {
                    name: '周四',
                    id: 4
                }, {
                    name: '周五',
                    id: 5
                }, {
                    name: '周六',
                    id: 6
                }, {
                    name: '周日',
                    id: 7
                }], timeList: [{
                    name: '上午',
                    id: 1
                }, {
                    name: '下午',
                    id: 2
                }, {
                    name: '夜门诊',
                    id: 3
                }],
                ruleForm: {
                    amount: '80',
                    appointmentAmount: 0,
                    appointmentBegin: 0,
                    averageVisitTime: 3,
                    binId: null,
                    binName: null,
                    clinicAddress: '',
                    depId: null,
                    depName: null,
                    doctorId: null,
                    doctorName: null,
                    dueDate: new Date(2050, 1, 1),
                    effectiveDate: new Date(),
                    endTime: null,
                    hospitalId: null,
                    id: null,
                    increase: 0,
                    sffId: null,
                    startTime: null,
                    status: null,
                    timeState: null,
                    week: 2,
                    comingWeeks: 2,
                    fortnightly: '0',
                    registrationFee: '0',
                    tip: "取号时间上午10点下午3点"
                },
                rules: {
                    amount: [
                        {required: true, validator: checkAmount, trigger: ['blur', 'change']}
                    ],
                    averageVisitTime: [
                        {required: true, validator: checkAverageVisitTime, trigger: ['blur', 'change']}
                    ],
                    appointmentAmount: [
                        {required: true, validator: checkAppointmentAmount, trigger: ['blur', 'change']}
                    ],
                    appointmentBegin: [
                        {required: true, validator: checkAppointmentBegin, trigger: ['blur', 'change']}
                    ], depId: [
                        {required: true, message: '请选择科室名称', trigger: 'change'}
                    ],
                    hospitalId: [
                        {required: true, message: '请选择医院名称', trigger: 'change'}
                    ], timeState: [
                        {required: true, message: '请选择上下午时段', trigger: 'change'}
                    ], binId: [
                        {required: true, message: '请选择挂号类型', trigger: 'change'}
                    ], doctorId: [
                        {required: true, message: '请选择医生', trigger: 'change'}
                    ], week: [
                        {required: true, message: '请选择星期', trigger: 'change'}
                    ],
                    dueDate: [
                        {required: true, message: '请选择失效时间', trigger: 'change'}
                    ],
                    effectiveDate: [
                        {required: true, message: '请选择生效时间', trigger: 'change'}
                    ],
                    startTime: [
                        {required: true, message: '请选择门诊开始时间', trigger: 'change'}
                    ],
                    endTime: [
                        {required: true, message: '请选择门诊结束时间', trigger: 'change'}
                    ], tip: [
                        {required: true, message: '请输入个性信息', trigger: 'blur'},
                        {min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur'}
                    ]
                },
                dialogTableVisible: false,
                dialogFormVisible: false,
                formLabelWidth: '120px'
            }
        },
        methods: {
            check_num: function () {
                console.log(this.ruleForm.amount)
                if (this.ruleForm.amount) {
                    this.ruleForm.amount = this.ruleForm.amount.toString().replace(/[^\.\d]/g, '');
                    this.ruleForm.amount = this.ruleForm.amount.toString().replace('.', '');
                    this.ruleForm.amount = parseInt(this.ruleForm.amount).toString()
                }

            },
            lazyLoad() {
                let params = [{
                    name: 'depName',
                    value: this.depName
                }, {name: 'doctorName', value: this.doctorName}, {
                    name: 'sync',
                    value: this.status
                }, {name: 'week', value: this.week}, {name: 'hospitalId', value: this.hospitalId}]
                if (this.status == 2) {
                    params = [{
                        name: 'depName',
                        value: this.depName
                    }, {name: 'doctorName', value: this.doctorName}, {
                        name: 'status',
                        value: ''
                    }, {name: 'week', value: this.week}, {name: 'hospitalId', value: this.hospitalId}]
                }
                axios.post("http://" + window.location.host + '/outRegPlan/select_list_wrapper_Page', {
                    "pageNum": this.currentPage,
                    "pageSize": this.pageSize,
                    "params": params
                }).then(res => {
                    this.tableData = res.data.data.content;
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },
            detail(index,row) {
                let originalSchedule = row.systemid
                let hospitalId = row.hospitalId
                let doctorName = encodeURI(this.doctorName)
                let doctorId = row.doctorId
                let currentPage = this.currentPage;
                let pageSize = this.pageSize;
                console.log(1,doctorName)
                location.href = `../schedulingTemplate/schedulingTemplate.html?originalSchedule=${originalSchedule}&hospitalId=${hospitalId}&doctorName=${doctorName}&doctorId=${doctorId}&currentPage=${currentPage}&pageSize=${pageSize}`
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize=val;
            },
            handleCurrentPageChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage=val;
                this.lazyLoad()
            },
            // resizeHandler() {
            //     this.tableHeight = window.innerHeight - 80
            // },
            chinese: function () {
                this.doctorName = this.doctorName.replace(/[^\u4E00-\u9FA5]/g, '');
                this.ruleForm.clinicAddress = this.ruleForm.clinicAddress.replace(/\s+/g, '');
            },
            dictInit: function () {
                axios.get("http://" + window.location.host + '/ordSchedulingTemplate/week', {}).then(res => {
                    this.isLabel = "(当前第" + res.data.data + "周)";
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });

                axios.post("http://" + window.location.host + '/hospital/select_list', {hospitalId: this.hospitalId}).then(res => {
                    this.hospitals = res.data.data;
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
                axios.post("http://" + window.location.host + '/pubDepartments/select_list', {
                    depName: '',
                    status: 0,
                    hospitalId: this.hospitalId
                }).then(res => {
                    this.departments = res.data.data;
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
                axios.post("http://" + window.location.host + '/pubBindInfo/select_list', {}).then(res => {
                    this.bindInfos = res.data.data;
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
                axios.post("http://" + window.location.host + '/pubDoctor/select_list', {
                    doctorName: "", hospitalId: this.hospitalId
                }).then(res => {
                    this.doctors = res.data.data;
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },
            init: function () {
                let that = this
                that.loading = false
                let params = [{
                    name: 'depName',
                    value: this.depName
                }, {name: 'doctorName', value: this.doctorName}, {
                    name: 'sync',
                    value: this.status
                }, {name: 'week', value: this.week}, {name: 'hospitalId', value: this.hospitalId}]
                if (this.status == 2) {
                    params = [{
                        name: 'depName',
                        value: this.depName
                    }, {name: 'doctorName', value: this.doctorName}, {name: 'status', value: ''}, {
                        name: 'week',
                        value: this.week
                    }, {name: 'hospitalId', value: this.hospitalId}]
                }
                axios.post("http://" + window.location.host + '/outRegPlan/select_list_wrapper_Page', {
                    "pageNum": this.currentPage,
                    "pageSize": this.pageSize,
                    "params": params
                }).then(res => {
                    this.tableData = res.data.data.content;
                    this.totalPage = res.data.data.totalPage
                    this.total = res.data.data.totalSize
                }).catch((e) => {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },
            extractHisData: function () {
                let loading = this.$loading({
                    lock: true,
                    text: '数据处理中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                axios.post("http://" + window.location.host + '/ordSchedulingTemplate/extractHisData', {}).then(res => {
                    loading.close();
                    this.init()
                    if (res.data.code == 500) {
                        this.$message({
                            showClose: true,
                            type: 'error',
                            message: res.data.msg
                        });
                    } else {
                        if (res.data.msg == "") {
                            this.$message({
                                showClose: true,
                                type: 'success',
                                message: "获取排班信息成功！"
                            });
                        } else {
                            this.$alert(res.data.msg.split(";").join("<br>"), '提示', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    // this.$message({
                                    //     type: 'info',
                                    //     message: `action: ${action}`
                                    // });
                                }
                            })
                        }

                    }
                }).catch((error) => {
                    loading.close();
                    this.init()
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: error.response.data.message
                    });
                });
            },
            createSchedulingBatch: function () {
                let loading = this.$loading({
                    lock: true,
                    text: '数据处理中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                axios.post("http://" + window.location.host + '/ordSchedulingTemplate/createSchedulingBatchAll', {}).then(res => {
                    loading.close();
                    this.init()
                    if (res.data.msg == "") {
                        this.$message({
                            type: 'success',
                            message: "批量生成排班信息成功！"
                        });
                    } else {
                        this.$alert(res.data.msg.split(";").join("<br>"), '提示', {
                            dangerouslyUseHTMLString: true,
                            confirmButtonText: '确定',
                            callback: action => {

                            }
                        })

                    }
                }).catch((error) => {
                    loading.close();
                    this.init()
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: error.response.data.message
                    });
                });
            },
            closeDiglog: function () {
                this.isEdit = false
                this.ruleForm = {
                    amount: 80,
                    appointmentAmount: 0,
                    appointmentBegin: 0,
                    averageVisitTime: 3,
                    binId: null,
                    binName: null,
                    clinicAddress: null,
                    depId: null,
                    depName: null,
                    doctorId: null,
                    doctorName: null,
                    dueDate: new Date(2050, 1, 1),
                    effectiveDate: new Date(),
                    endTime: null,
                    hospitalId: null,
                    id: null,
                    increase: 0,
                    sffId: null,
                    startTime: null,
                    status: null,
                    timeState: null,
                    week: 2,
                    comingWeeks: 2,
                    fortnightly: '0',
                    registrationFee: '0',
                    tip: "取号时间上午10点下午3点"
                }
            },
            handleCurrentChange(val) {
                this.currentUpRow = val;
                console.log(this.currentUpRow)
            },
            formatterHospital: function (row, column) {
                for (let i = 0; i < this.hospitals.length; i++) {
                    if (row.hospitalId == this.hospitals[i].id) {
                        return this.hospitals[i].hosName
                    }
                }
            },
            formatterWeek: function (row, column) {
                let week = ""
                switch (row.week) {
                    case 1:
                        week = "星期一";
                        break;
                    case 2:
                        week = "星期二";
                        break;
                    case 3:
                        week = "星期三";
                        break;
                    case 4:
                        week = "星期四";
                        break;
                    case 5:
                        week = "星期五";
                        break;
                    case 6:
                        week = "星期六";
                        break;
                    case 7:
                        week = "星期日";
                        break;
                    default:
                        week = "未知";
                }
                return week;
            },
            formatterTimeState: function (row, column) {
                let timeState = ""
                switch (row.timeState) {
                    case 1:
                        timeState = "上午";
                        break;
                    case 2:
                        timeState = "下午";
                        break;
                    case 3:
                        timeState = "夜门诊";
                        break;
                    default:
                        timeState = "未知";
                }
                return timeState;
            },
            createScheduling: function (index, row) {
                this.$confirm('此操立即生成排班, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let loading = this.$loading({
                        lock: true,
                        text: '数据处理中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)'
                    });
                    let params = new URLSearchParams()
                    params.append("id", row.id)
                    axios.post("http://" + window.location.host + '/ordSchedulingTemplate/createScheduling', params).then(res => {
                        console.log(res)
                        if (res.status == 500 || res.status == '500') {
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        } else {
                            if (res.data.msg == "") {
                                this.$message({
                                    type: 'success',
                                    message: "生成排班成功！"
                                });
                            } else {
                                this.$alert(res.data.msg.split(";").join("<br>"), '提示', {
                                    dangerouslyUseHTMLString: true,
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        // this.$message({
                                        //     type: 'warning',
                                        //     message: `action: ${action}`
                                        // });
                                    }
                                })

                            }

                        }
                        loading.close();
                    }).catch((error) => {
                        this.$message({
                            type: 'info',
                            message: error.response.data.message
                        });
                        loading.close();
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消生成排班信息'
                    });
                    loading.close();
                });
            },
            rTime: function (date) {
                let json_date = new Date(date).toJSON();
                date = new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
                date = new Date(date)
                var seperator1 = "-";
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                return year + seperator1 + month + seperator1 + strDate;
            },
            submitForm: function (ruleForm) {
                this.ruleForm.dueDate = this.rTime(this.ruleForm.dueDate);
                this.ruleForm.effectiveDate = this.rTime(this.ruleForm.effectiveDate);
                this.$refs[ruleForm].validate((valid) => {
                    if (valid) {
                        let URL = ""
                        if (this.ruleForm.id) {
                            URL = '/ordSchedulingTemplate/update_by_primary_key_selective'
                        } else {
                            URL = '/ordSchedulingTemplate/create'
                        }
                        axios.post("http://" + window.location.host + URL, this.ruleForm).then(res => {
                            this.$message({
                                type: 'success',
                                message: '保存成功!'
                            });
                            this.init()
                            this.dialogFormVisible = false
                        }).catch(function (error) {
                            alert(error.response.data.message)

                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: '表单验证不通过，不能保存!'
                        });
                        this.init()
                        return false;
                    }
                });
                this.isEdit = false
            },
            deleteRow: function (index, row) {
                this.$confirm('请谨慎操作，可能导致医生排班异常, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let sync = row.sync == '0' ? '1' : '0'
                    let msg;
                    if (sync == '1') {
                        msg = '停止同步HIS数据'
                    } else {
                        msg = '恢复同步HIS数据'
                    }
                    axios.post("http://" + window.location.host + '/outRegPlan/update_by_primary_key_selective',
                        {'systemid': row.systemid,'hospitalId':row.hospitalId, 'sync': sync}
                    ).then(res => {
                        this.init()
                        this.$message({
                            type: 'success',
                            message: msg
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            editRow: function (index, row) {
                this.$confirm('排班模板调整只针对下周生效，最近一周排班表调整 请在临时排班管理中调整, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    if (row.timeState == 1) {
                        this.optionTime = {
                            start: '07:30:00',
                            step: '00:15:00',
                            end: '21:30:00',
                            minTime: '07:30:00',
                            maxTime: '12:30:00'
                        }
                    } else if (row.timeState == 2) {
                        this.optionTime = {
                            start: '07:30:00',
                            step: '00:15:00',
                            end: '21:30:00',
                            minTime: '11:45:00',
                            maxTime: '21:30:00'
                        }
                    } else if (row.timeState == 3) {
                        this.optionTime = {
                            start: '16:45:00',
                            step: '00:15:00',
                            end: '21:30:00',
                            minTime: '16:45:00',
                            maxTime: '21:30:00'
                        }
                    }
                    this.ruleForm = row;
                    console.log(this.ruleForm)
                    this.isEdit = true
                    this.dialogFormVisible = true
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消调整'
                    });
                });

            },
            tableRowClassName({row, rowIndex}) {
                if (row.status == 1 || row.status == '1') {
                    return 'warning-row';
                } else if (row.status == 0 || row.status == '0') {
                    return 'success-row';
                } else if (row.status == 2 || row.status == '2') {
                    return 'error-row';
                }
                return '';
            },
            //设置指定行、列、具体单元格颜色
            cellStyle: function ({row, column, rowIndex, columnIndex}) {
                if (row.doctorSync == "0" && columnIndex == 2) {
                    return 'background-color: #00B83F'
                } else if (row.doctorSync == "1" && columnIndex == 2) {
                    return 'background-color: #E6A23C'
                }  else {
                    return ""
                }
            },
            getPageParam(param) {
                var query = decodeURI(window.location.search).substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == param) {
                        return pair[1];
                    }
                }
                return '';
            },
        },
        created() {
            console.log("dddd")
            this.doctorName = this.getPageParam("doctorName")
            console.log(4,this.doctorName)
            this.currentPage = this.getPageParam("currentPage")
            if (this.currentPage==''){
                this.currentPage=1
            }
            this.currentPage=parseInt(this.currentPage)
            this.pageSize = this.getPageParam("pageSize")
            if (this.pageSize==''){
                this.pageSize=15
            }
            this.pageSize=parseInt(this.pageSize)
            this.dictInit();
            this.init();
        },
        watch: {
            'ruleForm.hospitalId': function (val, oldval) {
                console.log("val, oldval", val, oldval)
                if (val != oldval && !this.isEdit) {
                    if (val != null && val != undefined) {
                        axios.post("http://" + window.location.host + '/pubDepartments/select_list', {
                            hospitalId: val, hospitalId: this.hospitalId
                        }).then(res => {
                            console.log(res)
                            this.departments = res.data.data;
                        }).catch((e) => {
                            this.$message({
                                showClose: true,
                                type: 'error',
                                message: "获取数据失败"
                            });
                        });
                        this.ruleForm.depId = null
                    }
                }
            },
            'ruleForm.depId': function (val, oldval) {
                if (val != oldval && !this.isEdit) {
                    if (val != null && val != undefined) {
                        axios.post("http://" + window.location.host + '/pubDoctor/select_list', {
                            depId: val, hospitalId: this.hospitalId
                        }).then(res => {
                            console.log(res)
                            this.doctors = res.data.data;
                        }).catch((e) => {
                            this.$message({
                                showClose: true,
                                type: 'error',
                                message: "获取数据失败"
                            });
                        });
                    }
                    this.ruleForm.doctorId = null;
                }
            },
            week: function (val, oldval) {
                if (val != oldval) {
                    // 0. 刷新后重置滚动距离
                    this.init()
                }
            },
            pageSize:function (newValue, oldValue) {
                this.lazyLoad()
            },
        },
        mounted:function(){
            this.$nextTick(function () {
                this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 80;
                // 监听窗口大小变化
                let self = this;
                window.onresize = function() {
                    self.tableHeight = window.innerHeight - self.$refs.table.$el.offsetTop - 80
                }
            })
            //this.$refs.table.$el.offsetTop：表格距离浏览器的高度
            //100表示你想要调整的表格距离底部的高度（你可以自己随意调整），因为我们一般都有放分页组件的，所以需要给它留一个高度　
        }
    });
</script>

</html>
